Skip to content

Fix schedule_all completion synchronization and lifetime - #2536

Open
Waterpine wants to merge 1 commit into
NVIDIA:mainfrom
Waterpine:fix/schedule-all-completion
Open

Waterpine wants to merge 1 commit into
NVIDIA:mainfrom
Waterpine:fix/schedule-all-completion

Conversation

@Waterpine

Copy link
Copy Markdown

This fixes two issues in schedule_all's completion protocol:

  • Child operations decrement the completion counter with relaxed ordering, which does not synchronize their result writes with the final receiver. Reading those results in the completion callback can therefore cause a data race.
  • A child can complete synchronously during start(). The final completion callback may destroy the parent operation while start() still accesses its mutex, flags, or task queue, causing a use-after-free.

Reserve an additional countdown reference for start() and release it only after enqueueing is finished and the start mutex has been unlocked. Use acquire-release ordering for the countdown decrements so the final completion observes the preceding workers' writes.

Testing

  • Added a regression test where a next-sender completes synchronously with set_stopped and the final receiver destroys the parent operation.
  • Added a Relacy test that writes independent results on worker threads and reads them after completion.
  • All 24 related test cases passed with AddressSanitizer and UndefinedBehaviorSanitizer on Linux x86-64 with GCC 13.
  • The Relacy test completed 100,000 schedules without a counterexample.
  • Passed the repository-wide clang-format 21 check, including the new regression test files.

@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test 610b25b

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants